package org.cyclone.order.hsql.preferences;

import org.cyclone.order.hsql.HsqlPlugin;
import org.cyclone.order.ui.preferences.EPreferences;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class HsqlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    private BooleanFieldEditor sameAsDbName;

    private IPreferenceStore store;

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
     */
    @Override
    protected void createFieldEditors() {

        StringFieldEditor dbName = new StringFieldEditor(EPreferences.HSQL_DBNAME.getName(), "Database Name", SWT.DEFAULT,
                getFieldEditorParent());

        DirectoryFieldEditor dbPath = new DirectoryFieldEditor(EPreferences.HSQL_DBPATH.getName(), "Database Path",
                getFieldEditorParent());

        sameAsDbName = new BooleanFieldEditor(EPreferences.HSQL_SAME_AS_DBNAME.getName(), "Set db file name same as db name",
                SWT.DEFAULT, getFieldEditorParent());

        addField(dbName);
        addField(dbPath);
        addField(sameAsDbName);

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize()
     */
    @Override
    protected void initialize() {
        super.initialize();
        sameAsDbName.setPropertyChangeListener(new IPropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if (store.getBoolean(EPreferences.HSQL_SAME_AS_DBNAME.getName())) {

                }

            }

        });

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
     */
    public void init(IWorkbench workbench) {
        this.store = HsqlPlugin.getDefault().getPreferenceStore();
        setPreferenceStore(store);
    }
}
